package com.youdoneed.community.forum.web;

import com.youdoneed.community.common.vo.ResultMessage;
import com.youdoneed.community.forum.service.ForummessageshieldrecordService;
import com.youdoneed.community.forum.vo.ShieldVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 屏蔽接口
 * Created by lid on 2017/7/19 0019.
 */
@RestController
@RequestMapping(value = "/shield", method = {RequestMethod.GET, RequestMethod.POST})
@Api(value = "屏蔽模块控制器", description = "屏蔽模块相关操作")
public class ForummessageshieldrecordController {

    private static final Logger logger = LoggerFactory.getLogger(ForummessageshieldrecordController.class);

    @Autowired
    ForummessageshieldrecordService forummessageshieldrecordService;

    @ResponseBody
    @RequestMapping(value = "/saveShieldRecord", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "保存屏蔽记录", value = "保存屏蔽记录")
    public ResultMessage<?> saveShieldRecord(@RequestBody ShieldVo vo) {
        forummessageshieldrecordService.saveForummessageshieldrecord(vo);
        return ResultMessage.newSuccess("保存屏蔽信息成功！");
    }

    /**
     * 判断用户是否屏蔽了某个人或者某个自媒体
     *
     * @param userId
     * @param shildUserId
     * @return ResultMessage
     * @author lid
     * @date 2017.7.27
     */
    @RequestMapping(value = "/hasShield", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(notes = "判断用户是否屏蔽", value = "判断用户是否屏蔽")
    public ResultMessage<Boolean> hasShield(String userId, String shildUserId) {
        Integer count = forummessageshieldrecordService.countHasShield(userId, shildUserId);
        logger.info("count:" + count);
        if (0 < count) {
            return ResultMessage.newSuccess("用户已屏蔽").setData(true);
        }
        return ResultMessage.newSuccess("用户未屏蔽").setData(false);
    }
}
